import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
let homepath=[
  {
    path: '/home/index',
    name: 'Index',
    component: () => import('../views/home/Index.vue'),
    meta:{
      title:"首页",
      icon:"el-icon-house"
    }
  },
  {
    path: '/home/text',
    name: 'Text',
    component: () => import('../views/home/Text.vue'),
    meta:{
      title:"文档",
      icon:"el-icon-chat-dot-square"
    }
  },
  {
    path: '/home/try',
    name: 'IndeTryx',
    component: () => import('../views/home/Try.vue'),
    meta:{
      title:"权限测试页",
      icon:"el-icon-sell"
    }
  },
  {
    path: '/home/picture',
    name: 'Picture',
    component: () => import('../views/home/Picture.vue'),
    meta:{
      title:"图标",
      icon:"el-icon-office-building"
    }
  },
  {
    path: '/home/intruduction',
    name: 'Intruduction',
    component: () => import('../views/home/Intruduction.vue'),
    meta:{
      title:"引导页",
      icon:"el-icon-goods"
    }
  },
  {
    path: '/home/table',
    name: 'Table',
    component: () => import('../views/home/Table.vue'),
    meta:{
      title:"Table",
      icon:"el-icon-collection"
    }
  },
  
]
const routes = [
  {
    path: '/',
   redirect: '/home',  // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children:homepath
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

let whiteList=["/login","/home/index"];
router.beforeEach((to, from, next) => {
  let token=window.localStorage.getItem("token")
  if (token || whiteList.includes(to.path)){
    next()
  } else {
    next("/login")
  }
  
})
export default router
